<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/3 0003
 * Time: 下午 4:20
 */
namespace app\admin\model;

use think\Model;

class AdminUser extends Model{
    protected $autoWriteTimestamp = true;
    /**
     * 新增用户
     * @param mixed|string $data
     * @return mixed
     */
    public function add($data){
        if(!is_array($data)){
            exception('传递的数据不合法');
        }
        $this->allowField(true)->save($data);
        return $this->id;
    }

    public function login($data){
        if(!is_array($data)){
            exception('传递的数据不合法');
        }
        if(!captcha_check($data['code'])){
            exception('验证码错误');
        }else{
            $user = $this->get(['username' => $data['username']]);
            if(!$user || $user->status!=1){
                exception('该用户不存在!');
            }else{
                if(md5($data['password'].$user['salt']) != $user['password']){
                    exception('用户名或密码错误！');
                }else{
                    //登录成功
                }
            }

        }

    }

}